package com.stu.controller.admin;

import com.stu.Dto.DormitoryRepairDTO;
import com.stu.Dto.DormitoryReplyDTO;
import com.stu.Dto.NoticeDTO;
import com.stu.Dto.ViolationInformationDto;
import com.stu.pojo.PageBean;
import com.stu.pojo.ViolationInformation;
import com.stu.result.Result;
import com.stu.serive.AdminOperateService;
import com.stu.serive.CounsellorOperateService;
import com.stu.serive.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RestController
@RequestMapping("/admin")
public class AdminOperateController {

    @Autowired
    private AdminOperateService adminOperateService;
    @Autowired
    private NoticeService noticeService;

    /**
     * 审核奖学金审批
     * @param result
     * @return
     */
    @PostMapping("/examineScholarship")
    private Result examineScholarship(@RequestParam Integer result, Integer id){
        adminOperateService.examineScholarship(result, id);
        return Result.success();
    }

    /**
     * 审核处分解除
     * @param result
     * @param id
     * @return
     */
    @PostMapping("/examineViolation")
    private Result examineViolation(@RequestParam Integer result, Integer id){
        adminOperateService.examineViolation(result, id);
        return Result.success();
    }

    /**
     * 发布通知
     */
    @PostMapping("/Notice")
    private Result insertNotice(@RequestBody NoticeDTO noticeDTO){
        adminOperateService.insertNotice(noticeDTO);
        return Result.success();
    }

    /**
     * 修改通知
     */
    @PostMapping("updateNotice")
    private Result updateNotice(@RequestBody NoticeDTO noticeDTO){
        adminOperateService.updateNotice(noticeDTO);
        return Result.success();
    }

    /**
     * 查询通知
     */
    @GetMapping("/notice")//分页查询操作
    public Result notice(@RequestParam(defaultValue = "1") Integer page,//@RequestParam 用于将指定的请求参数赋值给方法中的形参中
                         @RequestParam(defaultValue = "1") Integer pageSize,
                         String informationClass, String key,
                         //@DateTimeFormat 指定时间的格式
                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("分页查询，参数：{}，{}, {}, {}, {}, {}", page, pageSize,informationClass,key,begin,end);//查询的页面，展示的数据
        //  PageBean 是一个专门用于分页查询的方法，传入指定的参数即可
        PageBean pageBean = noticeService.notice(page, pageSize, informationClass, key, begin, end);
        return Result.success(pageBean);
    }

    /**
     * 处理宿舍维修信息
     */
    @PostMapping("/dormitoryRepair")
    private Result updateDormitoryRepair(@RequestBody DormitoryReplyDTO dormitoryReplyDTO){
        adminOperateService.updateDormitoryRepair(dormitoryReplyDTO);
        return Result.success();
    }

    /**
     * 添加学生处分信息 用学号做判断
     */
    @PostMapping("addViolationInformation")
    private Result addViolationInformation(@RequestBody ViolationInformationDto dto){
        adminOperateService.addViolationInformation(dto);
        return Result.success();
    }

}
